* FIG 3: DRAW A MAP OF THE ORIGIN OF TAXPAYERS WHO MOVED TO OW BEFORE / AFTER THE REFORM
// NOTE: data needed for this do-file cannot be shared due to privacy reasons

/* following packages need to be installed:
ssc install spmap
*/

version 16.1

clear all
cap log close 
cap clear matrix
set more off
cap set scheme mygraphs


cd "$mypathRR/Datasets/"


use "movers/origin_60_80_before-after.dta", clear 

// rename canton variable for later merge
rename A1 KT

// make a full balanced panel for proper display of map
recode KT (98 = 28 ) (99 =29)
label define cant 28 `"A"' 29 `"?"', modify
xtset A_treat KT
tsfill, full


merge m:1 KT using "chdb.dta"
drop _merge
drop if KT==.
drop if KT==0

sort A_treat KT

format %4.2f pct_b 
replace pct_b=round(pct_b, 0.1)


* DRAW MAPS *
cd "$mypathRR/Results"

// with same brackets:
// treated inmovers, before 2006
sum pct_b if A_treat==12 & KT==28
local abroad : di %3.1f `= r(min)'
spmap pct_b if A_treat==12 using "$mypathRR/Datasets/chcoord.dta", id(cant) clmethod(custom) clbreaks(0 2 3 7.5 10 12.5 15 17.5 25) fcolor(Blues2) ///
     legend(ring(0) position(11) bmargin(l=-19) size(*1.3) ) ndlabel("0" )  legtitle("Origin of in-movers in %" " " "from abroad: `abroad'")    ysize(8) xsize(15) ///
    line(data("$mypathRR/Datasets/chcoord_treat.dta") by(treat) color(black red) size(thin)) ///
    polygon(data("$mypathRR/Datasets/chcoord.dta") select(keep if _ID==6) fcolor(red*0.15) ocolor(red*1.3) osize(thick))
	
	graph export "Fig_3a)-origin_map_treated_before2006_samescale.pdf", as(pdf) replace

// treated inmovers, after 2006 11
sum pct_b if A_treat==11 & KT==28
local abroad : di %3.1f `= r(min)'
spmap pct_b if A_treat==11 using "$mypathRR/Datasets/chcoord.dta", id(cant) clmethod(custom) clbreaks(0 2 3 7.5 10 12.5 15 17.5 25) fcolor(Blues2) ///
     legend(ring(0) position(11) bmargin(l=-19) size(*1.3) ) ndlabel("0" )  legtitle("Origin of in-movers in %" " " "from abroad: `abroad'")    ysize(8) xsize(15) ///
    line(data("$mypathRR/Datasets/chcoord_treat.dta") by(treat) color(black red) size(thin)) ///
    polygon(data("$mypathRR/Datasets/chcoord.dta") select(keep if _ID==6) fcolor(red*0.15) ocolor(red*1.3) osize(thick))
	
	graph export "Fig_3b)-origin_map_treated_after2006_samescale.pdf", as(pdf) replace

	
								* * * * *  E N D  * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
